﻿using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using Ricciolo.PaperBoy.Feeds;
using System.Windows;


namespace Project_CFT2.ViewModel
{
    internal class FurnitureViewModel2 : ViewModelBase
    {
        private readonly Feed _feed;
        private myFurnitureDataItem _dataItem;
        private string t;
        private string im;
        private int length;
        private int width;
        private int height;
        private double price;
        private string description;
        private int count = 0;
        private int number = 0;

        //private ReadOnlyCollection<ViewModelBase> _items;
       // private static DataClasses1DataContext _dataDC = new DataClasses1DataContext();
        private ObservableFurnitureItems _furnitureItems;

        public FurnitureViewModel2(myFurnitureDataItem feed)
        {
            _dataItem = feed as myFurnitureDataItem;
            t = _dataItem.name;
            im = _dataItem.im_src;
            length = _dataItem.length;
            width = _dataItem.width;
            price = _dataItem.price;
            description = _dataItem.description;
            count += 1;
            number = count;
           // _furnitureItems = new ObservableFurnitureItems(_dataDC);
            //_items = _furnitureItems;
        }

        protected override string GetTitle() { return _dataItem.name; }

        public bool HasUnreadItems
        {
            get { return false; }
        }
        public string Title
        {
            get
            {
                return t;
            }
        }

        public int UnreadItemCount
        {
            get { return 0; }
        }

        public string TitleAndUnreadItemCount
        {

            get
            {

                return t;
            }
        }
        public string strDescription
        {

            get
            {

                return description;
            }
        }
        public string Image
        {
            get
            {
                return im;
            }
        }
        public int Length
        {
            get
            {
                return length;
            }
        }
        public int Width
        {
            get
            {
                return width;
            }
        }
        public int Height
        {
            get
            {
                return height;
            }
        }
        public double Price
        {
            get
            {
                return price;
            }
        }

        public string strLength
        {
            get
            {
                return ((double)length / 100.0).ToString() + "m";
            }
        }
        public string strWidth
        {
            get
            {
                return ((double)width / 100.0).ToString() + "m";
            }
        }
        public string strHeight
        {
            get
            {
                return ((double)height / 100.0).ToString() + "m";
            }
        }
        public string strPrice
        {
            get
            {
                return "$" + price.ToString("#0.00");
            }
        }


        /*      public ReadOnlyCollection<ViewModelBase> Items
              {
                  get
                  {
                      if (_items == null)
                      {
                          var bw = new BackgroundWorker();
                          bw.DoWork += RefreshItems;
                          bw.RunWorkerAsync();
                      }
                      return _items;
                  }
              }
      */
        public ObservableFurnitureItems Items
        {
            get
            {

                return _furnitureItems;
            }
        }
        void RefreshItems(object sender, DoWorkEventArgs e)
        {
            _feed.Items.Refresh(true);
            LoadItems();
        }

        private void LoadItems()
        {
            //          var itemsList = new List<ViewModelBase>();

            //           foreach (var item in _feed.Items)
            //             itemsList.Add(new FeedItemViewModel(item));

            //       _items = new ReadOnlyCollection<ViewModelBase>(itemsList);
            //_furnitureItems = new ObservableFurnitureItems(_dataDC);

            RaisePropertyChanged("Items");
            RaisePropertyChanged("HasUnreadItems");
            RaisePropertyChanged("UnreadItemCountString");
            RaisePropertyChanged("TitleAndUnreadItemCount");
            RaisePropertyChanged("Favicon");
            RaisePropertyChanged("FaviconBrush");
        }
    }
}